# Maintainer: Jelle van der Waa <jelle@archlinux.org>

pkgname=python-django-csp
pkgver=3.7
pkgrel=3
pkgdesc="Django-CSP adds Content-Security-Policy headers to Django"
arch=('any')
url="https://github.com/mozilla/django-csp"
license=('BSD')
makedepends=('python-setuptools')
checkdepends=('python-pytest' 'python-pytest-django' 'python-six')
depends=('python-django' 'python-jinja')
source=($pkgname-$pkgver.tar.gz::https://github.com/mozilla/django-csp/archive/refs/tags/${pkgver}.tar.gz
	tests-add-get_response-arg-to-middlware-init.patch)
sha512sums=('d15ecae2a59e47151f3b04d78138fbe5c22967e0366595324b41fdd3b3f8af2bf7a44606f329b853c6ebb14a590e63d54d02fb26a7248e04789d1c54410fb5ee'
            '0329d0dd64341936ab10e8966f8a37be2bd2058e20fbda7bada0a536565ba6a583b8ea8ca734b76b28fd593d5709988fb14fcf434af65aed0fe7d23687d3db86')

prepare() {
  cd "django-csp-$pkgver"
  sed -i 's/--pep8 --flakes//' setup.cfg

  patch -Np1 -i ${srcdir}/tests-add-get_response-arg-to-middlware-init.patch
}

build() {
  cd "django-csp-$pkgver"
  python setup.py build
}

check() {
  cd "django-csp-$pkgver"
  PYTHONPATH=. pytest csp/tests
}

package() {
  cd "django-csp-$pkgver"
  python setup.py install --skip-build \
                          --optimize=1 \
                          --root="${pkgdir}"
  install -vDm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
}
